package Beans;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.model.SelectItem;

import DAOJPA.DAOFilmJPA;
import DAOJPA.DAORecompenseJPA;
import DAOJPA.DAORecompenserFilmJPA;
import DAOJPA.DAORecompenserPersonneJPA;
import personne.Personne;
import film.Film;
import recompenses.Recompense;
import recompenses.RecompenserFilm;
import recompenses.RecompenserPersonne;

@ManagedBean
@RequestScoped
public class BeanRecompenses implements Serializable{

	/**
	 * 
	 */
	
	private static final long serialVersionUID = 1L;
	
	private Film film = new Film();
	private Personne personne = new Personne();
	private Recompense rec = new Recompense();
	private Date date;
	private String type;
	private int code;
	private RecompenserFilm recFilm = new RecompenserFilm();
	private RecompenserPersonne recPersonne = new RecompenserPersonne();
	
	
	public void ajouterRecFilm()
	{
		this.recFilm.setValide(0);
		DAORecompenserFilmJPA.getInstance().save(this.recFilm);
	}
	
	
	public void suprimerRecFilm()
	{
		DAORecompenserFilmJPA.getInstance().delete(this.recFilm);
	}
	
	
	public void ajouterRecPersonne()
	{
		this.recPersonne.setValide(0);
		DAORecompenserPersonneJPA.getInstance().save(this.recPersonne);	
	}
	
	
	public void suprimerRecPersonne()
	{
		DAORecompenserPersonneJPA.getInstance().delete(this.recPersonne);
	}
	
	
	public List<RecompenserFilm> getInvalideRecFilm()
	{
		return DAORecompenserFilmJPA.getInstance().getRecompenseInvalide();
	}
	
	
	public List<RecompenserPersonne> getInvalideRecPersonne()
	{
		return DAORecompenserPersonneJPA.getInstance().getRecompenseInvalide();	
	}
	
	
	public List<SelectItem> getRecompenses()
	{
		List<Recompense> l = DAORecompenseJPA.getInstance().loadAll();
		List<SelectItem> listItems = new ArrayList<SelectItem>();
		for (int i = 0 ; i < l.size() ; i++)
		{
			listItems.add(new SelectItem(l.get(i).getCode_rec(), l.get(i).getTitre()));
		}
		
		
		return listItems;
	}
	
	
	public Date getDate() {
		return date;
	}


	public void setDate(Date date) {
		this.date = date;
	}


	public String getType() {
		return type;
	}


	public void setType(String type) {
		this.type = type;
	}



	public Film getFilm() {
		return film;
	}


	public void setFilm(Film film) {
		this.film = film;
	}


	public Personne getPersonne() {
		return personne;
	}


	public void setPersonne(Personne personne) {
		this.personne = personne;
	}


	public Recompense getRec() {
		return rec;
	}


	public void setRec(Recompense rec) {
		this.rec = rec;
	}


	public int getCode() {
		return code;
	}


	public void setCode(int code) {
		this.code = code;
	}


	public RecompenserFilm getRecFilm() {
		return recFilm;
	}


	public void setRecFilm(RecompenserFilm recFilm) {
		this.recFilm = recFilm;
	}


	public RecompenserPersonne getRecPersonne() {
		return recPersonne;
	}


	public void setRecPersonne(RecompenserPersonne recPersonne) {
		this.recPersonne = recPersonne;
	}
	

	
}
